﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace huaguwang
{
      /// <summary>
      /// 数据访问类:T_MicroBloggingComment
      /// 创建时间2010年12月31日 09:46:51
      /// 创建人:
      /// </summary>
      /// <remarks>按照公司编码规范,严禁修改此类</remarks>
      public class D_T_MicroBloggingComment
      {
            public D_T_MicroBloggingComment()
            { }
            #region  Method
            /// <summary>
            /// 是否存在该记录
            /// 没有flag判断的
            /// </summary>
            public bool Exists(int id)
            {
                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("select count(1) from T_MicroBloggingComment");
                  strSql.Append(" where id=@id ");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
                  parameters[0].Value = id;

                  return MSSQLHelper.SQLConType.C1.Exp_Exists(strSql.ToString(), parameters);
            }

            /// <summary>
            /// 是否存在该记录
            /// 带有flag判断的
            /// </summary>
            public bool ExistsFlag(int id)
            {
                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("select count(1) from T_MicroBloggingComment");
                  strSql.Append(" where id=@id and  Flag=1 ");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
                  parameters[0].Value = id;

                  return MSSQLHelper.SQLConType.C1.Exp_Exists(strSql.ToString(), parameters);
            }


            /// <summary>
            /// 增加一条数据
            /// </summary>
            public int Add(huaguwang.M_T_MicroBloggingComment model)
            {
                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("insert into T_MicroBloggingComment(");
                  strSql.Append("MicroBlogID,MemberID,MemberIP,RemarkContent,RemarkDate,Flag)");
                  strSql.Append(" values (");
                  strSql.Append("@MicroBlogID,@MemberID,@MemberIP,@RemarkContent,@RemarkDate,@Flag)");
                  strSql.Append(";select @@IDENTITY");
                  SqlParameter[] parameters = {
					new SqlParameter("@MicroBlogID", SqlDbType.Int,4),
					new SqlParameter("@MemberID", SqlDbType.Int,4),
					new SqlParameter("@MemberIP", SqlDbType.NVarChar,50),
					new SqlParameter("@RemarkContent", SqlDbType.NVarChar,1000),
					new SqlParameter("@RemarkDate", SqlDbType.SmallDateTime),
					new SqlParameter("@Flag", SqlDbType.Bit,1)};
                  parameters[0].Value = model.MicroBlogID;
                  parameters[1].Value = model.MemberID;
                  parameters[2].Value = model.MemberIP;
                  parameters[3].Value = model.RemarkContent;
                  parameters[4].Value = model.RemarkDate;
                  //flag标记在增加的使用永远为true
                  parameters[5].Value = true;

                  object obj = MSSQLHelper.SQLConType.C1.Exp_GetSingle(strSql.ToString(), parameters);
                  if (obj == null)
                  {
                        return 0;
                  }
                  else
                  {
                        return Convert.ToInt32(obj);
                  }
            }
            /// <summary>
            /// 更新一条数据
            /// </summary>
            public int Update(huaguwang.M_T_MicroBloggingComment model)
            {
                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("update T_MicroBloggingComment set ");
                  strSql.Append("MicroBlogID=@MicroBlogID,");
                  strSql.Append("MemberID=@MemberID,");
                  strSql.Append("MemberIP=@MemberIP,");
                  strSql.Append("RemarkContent=@RemarkContent,");
                  strSql.Append("RemarkDate=@RemarkDate");
                  strSql.Append(" where id=@id");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@MicroBlogID", SqlDbType.Int,4),
					new SqlParameter("@MemberID", SqlDbType.Int,4),
					new SqlParameter("@MemberIP", SqlDbType.NVarChar,50),
					new SqlParameter("@RemarkContent", SqlDbType.NVarChar,1000),
					new SqlParameter("@RemarkDate", SqlDbType.SmallDateTime),
					new SqlParameter("@Flag", SqlDbType.Bit,1)};
                  parameters[0].Value = model.id;
                  parameters[1].Value = model.MicroBlogID;
                  parameters[2].Value = model.MemberID;
                  parameters[3].Value = model.MemberIP;
                  parameters[4].Value = model.RemarkContent;
                  parameters[5].Value = model.RemarkDate;
                  parameters[6].Value = model.Flag;

                  int rows = MSSQLHelper.SQLConType.C1.Exp_ExecuteSql(strSql.ToString(), parameters);
                  if (rows > 0)
                  {
                        return model.id;
                  }
                  else
                  {
                        return 0;
                  }
            }

            /// <summary>
            /// 逻辑删除一条资料
            /// </summary>
            public int UpdateFlag(int id)
            {

                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("update T_MicroBloggingComment ");
                  strSql.Append(" set flag=0 where id=@id");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
                  parameters[0].Value = id;

                  int rows = MSSQLHelper.SQLConType.C1.Exp_ExecuteSql(strSql.ToString(), parameters);
                  if (rows > 0)
                  {
                        return id;
                  }
                  else
                  {
                        return 0;
                  }
            }

            /// <summary>
            /// 逻辑删除多条资料
            /// </summary>
            public int UpdateFlag(List<int> list)
            {

                  return MSSQLHelper.SQLConType.C1.Exp_UpdateFlag("T_MicroBloggingComment", list);
            }


            /// <summary>
            /// 得到一个对象实体
            /// </summary>
            public huaguwang.M_T_MicroBloggingComment GetModel(int id)
            {

                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("select  top 1 id,MicroBlogID,MemberID,MemberIP,RemarkContent,RemarkDate,Flag from T_MicroBloggingComment ");
                  strSql.Append(" where id=@id");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
                  parameters[0].Value = id;

                  huaguwang.M_T_MicroBloggingComment model = new huaguwang.M_T_MicroBloggingComment();
                  DataSet ds = MSSQLHelper.SQLConType.C1.Exp_Query(strSql.ToString(), parameters);
                  if (ds.Tables[0].Rows.Count > 0)
                  {
                        if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                        {
                              model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["MicroBlogID"].ToString() != "")
                        {
                              model.MicroBlogID = int.Parse(ds.Tables[0].Rows[0]["MicroBlogID"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["MemberID"].ToString() != "")
                        {
                              model.MemberID = int.Parse(ds.Tables[0].Rows[0]["MemberID"].ToString());
                        }
                        model.MemberIP = ds.Tables[0].Rows[0]["MemberIP"].ToString();
                        model.RemarkContent = ds.Tables[0].Rows[0]["RemarkContent"].ToString();
                        if (ds.Tables[0].Rows[0]["RemarkDate"].ToString() != "")
                        {
                              model.RemarkDate = DateTime.Parse(ds.Tables[0].Rows[0]["RemarkDate"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["Flag"].ToString() != "")
                        {
                              if ((ds.Tables[0].Rows[0]["Flag"].ToString() == "1") || (ds.Tables[0].Rows[0]["Flag"].ToString().ToLower() == "true"))
                              {
                                    model.Flag = true;
                              }
                              else
                              {
                                    model.Flag = false;
                              }
                        }
                        return model;
                  }
                  else
                  {
                        return null;
                  }
            }


            /// <summary>
            /// 得到一个对象实体
            /// 带有flag标签条件的
            /// </summary>
            public huaguwang.M_T_MicroBloggingComment GetModelFlag(int id)
            {

                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("select  top 1 id,MicroBlogID,MemberID,MemberIP,RemarkContent,RemarkDate,Flag from T_MicroBloggingComment ");
                  strSql.Append(" where id=@id and Flag=1 ");
                  SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
                  parameters[0].Value = id;

                  huaguwang.M_T_MicroBloggingComment model = new huaguwang.M_T_MicroBloggingComment();
                  DataSet ds = MSSQLHelper.SQLConType.C1.Exp_Query(strSql.ToString(), parameters);
                  if (ds.Tables[0].Rows.Count > 0)
                  {
                        if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                        {
                              model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["MicroBlogID"].ToString() != "")
                        {
                              model.MicroBlogID = int.Parse(ds.Tables[0].Rows[0]["MicroBlogID"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["MemberID"].ToString() != "")
                        {
                              model.MemberID = int.Parse(ds.Tables[0].Rows[0]["MemberID"].ToString());
                        }
                        model.MemberIP = ds.Tables[0].Rows[0]["MemberIP"].ToString();
                        model.RemarkContent = ds.Tables[0].Rows[0]["RemarkContent"].ToString();
                        if (ds.Tables[0].Rows[0]["RemarkDate"].ToString() != "")
                        {
                              model.RemarkDate = DateTime.Parse(ds.Tables[0].Rows[0]["RemarkDate"].ToString());
                        }
                        if (ds.Tables[0].Rows[0]["Flag"].ToString() != "")
                        {
                              if ((ds.Tables[0].Rows[0]["Flag"].ToString() == "1") || (ds.Tables[0].Rows[0]["Flag"].ToString().ToLower() == "true"))
                              {
                                    model.Flag = true;
                              }
                              else
                              {
                                    model.Flag = false;
                              }
                        }
                        return model;
                  }
                  else
                  {
                        return null;
                  }
            }

            /// <summary>
            /// 获取所有资料,如果没有资料不会返回null 
            /// </summary>
            public List<huaguwang.M_T_MicroBloggingComment> GetList(string strWhere, SqlParameter[] parameters)
            {
                  StringBuilder strSql = new StringBuilder();
                  strSql.Append("select id,MicroBlogID,MemberID,MemberIP,RemarkContent,RemarkDate,Flag ");
                  strSql.Append(" FROM T_MicroBloggingComment where flag=1 ");
                  if (strWhere.Trim() != "")
                  {
                        strSql.Append(" and " + strWhere);
                  }
                  var list = MSSQLHelper.SQLConType.C1.Exp_GetList(strSql.ToString(),
                  dr => DataRowToModel(dr), parameters);
                  return (list.Count > 0) ? list : new List<huaguwang.M_T_MicroBloggingComment>();
            }

            /// <summary>
            /// 获取单表的分页资料 
            /// </summary>
            public List<huaguwang.M_T_MicroBloggingComment> GetOneTablePage(int Begin, int Page, string strWhere, SqlParameter[] parameters)
            {
                  if (strWhere.Exp_Trim().Length > 0)
                  {
                        strWhere = " a.flag=1 and " + strWhere;
                  }
                  else
                  {
                        strWhere = " a.flag=1  ";
                  }
                  string strSQL = ExpandMSSQL.GetPageSQL(
                        Begin,
                        Page,
                        "a.id,a.MicroBlogID,a.MemberID,a.MemberIP,a.RemarkContent,a.RemarkDate,a.Flag",
                        "T_MicroBloggingComment as a ",
                        "a.id",
                        strWhere,
                        "a.id  desc");
                  var list = MSSQLHelper.SQLConType.C1.Exp_GetList(strSQL,
                  dr => DataRowToModel(dr), parameters);
                  return (list.Count > 0) ? list : new List<huaguwang.M_T_MicroBloggingComment>();
            }

            /// <summary>
            /// 获取单表的分页资料 
            /// </summary>
            public int GetOneTablePageCount(string strWhere, SqlParameter[] parameters)
            {
                  if (strWhere.Exp_Trim().Length > 0)
                  {
                        strWhere = " a.flag=1 and " + strWhere;
                  }
                  else
                  {
                        strWhere = " a.flag=1  ";
                  }
                  string strSQL = ExpandMSSQL.GetPageSQL(
                        "T_MicroBloggingComment as a ",
                        strWhere);
                  return MSSQLHelper.SQLConType.C1.Exp_GetSingle(strSQL, parameters).Exp_IntTryParse();
            }

            /// <summary>
            /// 把dr转换成model的方法
            /// </summary>
            public huaguwang.M_T_MicroBloggingComment DataRowToModel(DataRow dr)
            {
                  var model = new huaguwang.M_T_MicroBloggingComment();
                  if (dr["id"].ToString() != "")
                  {
                        model.id = int.Parse(dr["id"].ToString());
                  }
                  if (dr["MicroBlogID"].ToString() != "")
                  {
                        model.MicroBlogID = int.Parse(dr["MicroBlogID"].ToString());
                  }
                  if (dr["MemberID"].ToString() != "")
                  {
                        model.MemberID = int.Parse(dr["MemberID"].ToString());
                  }
                  model.MemberIP = dr["MemberIP"].ToString();
                  model.RemarkContent = dr["RemarkContent"].ToString();
                  if (dr["RemarkDate"].ToString() != "")
                  {
                        model.RemarkDate = DateTime.Parse(dr["RemarkDate"].ToString());
                  }
                  if (dr["Flag"].ToString() != "")
                  {
                        if ((dr["Flag"].ToString() == "1") || (dr["Flag"].ToString().ToLower() == "true"))
                        {
                              model.Flag = true;
                        }
                        else
                        {
                              model.Flag = false;
                        }
                  }
                  return model;
            }

            #endregion  Method
      }
}

